import mylist2.MyArrayList;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


/**
 * 类的调用者
 */
public class Test2 {
    public static void main3(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(3);
        list.add(2, 15);
        list.add(2);
        System.out.println(list);

        List<Integer> sub= list.subList(1,3);
        sub.set(0,888);
        System.out.println(sub);
        System.out.println(list);

        Iterator<Integer> it =  list.iterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");//自动向下执行
        }
        System.out.println();



        /*System.out.println(list);
        System.out.println(list.indexOf(2));
        System.out.println(list.lastIndexOf(2));
        System.out.println(list);*/


        //list.remove(2);
        //list.remove(new Integer(2));
        //System.out.println(list.get(2));
        //System.out.println(list.set(1, 999));
        //System.out.println(list);
        //System.out.println(list.contains(5));


        System.out.println("=======================");
        //ArrayList<Integer> list2 = new ArrayList<>(list);
        ArrayList<Integer> list2 = new ArrayList<>();
        list2.addAll(list);
        list2.add(666);
        list2.add(888);
        System.out.println(list2);

        //System.out.println(list.size());

    }


    public static void main2(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(12);
        list.add(13);
        list.add(14);
        list.add(15);
        System.out.println(list);
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();
        System.out.println("==================");

        for (Integer x : list) {
            System.out.print(x + " ");
        }
        System.out.println();

        ArrayList<Integer> list2 = new ArrayList<>(10);
        list2.add(111);
        list2.add(222);
        list2.add(333);

        ArrayList<Number> list3 = new ArrayList<>(list2);
        list3.add(555);
        list3.add(666);
        list3.add(777);
        System.out.println(list3);
    }


    public static void main1(String[] args) {
        MyArrayList list = new MyArrayList();
        list.add(10);//0
        list.add(20);//1
        list.add(30);//2
        list.add(3, 50);
        list.add(0, 60);
        list.display();

        System.out.println(list.contains(20));
        System.out.println(list.indexOf(111));
        System.out.println(list.get(0));
        list.display();
        System.out.println(list.size());
        System.out.println("=====================");

        list.set(2, 999);
        list.display();

        list.remove(22);
        list.display();

        System.out.println("=====================");

        list.clear();
        list.display();
    }
}
